package com.jcj.pojomessagepack;


import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.msgpack.MessagePack;

/**
 * 通过扩展MessageToMessageDecoder来自定义编码器
 */
public class MessagePackEncoder extends MessageToByteEncoder<Infomation> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, Infomation infomation, ByteBuf byteBuf) throws Exception {

        MessagePack messagePack = new MessagePack();

        //进行序列化(编码)
        byte[] raw = messagePack.write(infomation);
        byteBuf.writeBytes(raw);

    }
}
